package org.snusmumr.android.media.widget;

import org.snusmumr.android.media.R;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.widget.Button;

public class ColoredButton extends Button {
	private ShapeDrawable mDrawable;
	private int color;

    public ColoredButton(Context context, Integer color) {
        super(context);
        this.color = color != null ? color : R.color.red;

        mDrawable = new ShapeDrawable(new RectShape());
        mDrawable.getPaint().setColor(this.color);
    }

    protected void onDraw(Canvas canvas) {
        Rect rect = canvas.getClipBounds();
    	mDrawable.setBounds(rect.left + 17, 
    						rect.top + 12, 
    						rect.right - 17, 
    						rect.bottom -17);
        mDrawable.draw(canvas);
    }
    
    public void setColor(int color) {
		this.color = color;
		mDrawable.getPaint().setColor(color);
		invalidate();
	}
    
    public int getColor() {
		return color;
	}
}
